package Lee_code;

/**
 * @author blh
 * @date 2024年10月30日 10:59
 */
public class Lee_3216_1030 {
    public String getSmallestString(String s) {
        int len = s.length();
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0; i < len - 1; i++) {
            if (judge(sb.charAt(i), sb.charAt(i + 1))
                    && Character.getNumericValue(sb.charAt(i)) > Character.getNumericValue(sb.charAt(i + 1))) {
                char temp1 = sb.charAt(i);
                char temp2 = sb.charAt(i + 1);
                sb.replace(i, i + 1, String.valueOf(temp2));
                sb.replace(i + 1, i + 2, String.valueOf(temp1));
                break;
            }
        }
        return sb.toString();
    }

    public boolean judge(char char1, char char2) {
        int num1 = Character.getNumericValue(char1);
        int num2 = Character.getNumericValue(char2);
        return (num1 % 2) == (num2 % 2);
    }
}
